package com.ciwong.epaper.modules.epaper.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ciwong.epaper.R;

import java.util.ArrayList;
import java.util.List;

public class UserDKImgGridViewAdapter extends BaseAdapter {

    private Context mContext;
    private List<String> list = new ArrayList<>();
    private GridView gridView;

    private ImageView user_dk_child_img;

    private LinearLayout user_dk_count;

    private TextView user_dk_count_text2;

    private String videoUri;

    public UserDKImgGridViewAdapter(Context mContext,List<String> list,String videoUri){
        this.mContext = mContext;
        this.list = list;
        this.videoUri = videoUri;
    }



    @Override
    public int getCount() {
        if ( "".equals(videoUri) && list.size()>2){
            return 3;
        }else if ( !"".equals(videoUri) && list.size()>2){
            return 2;
        }else {
            return list.size();
        }
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {

        if (null == view) {
            view = View.inflate(mContext, R.layout.activity_user_dk_img_child, null);
            user_dk_child_img = (ImageView) view.findViewById(R.id.user_dk_child_img);
            user_dk_count = (LinearLayout) view.findViewById(R.id.user_dk_count);
            user_dk_count_text2 = (TextView) view.findViewById(R.id.user_dk_count_text2);
        }
        Glide.with(mContext).load(Uri.parse(list.get(i))).into(user_dk_child_img);
        int count = list.size();
        if ("".equals(videoUri) && list.size()>2 && i == 2) {
            user_dk_count_text2.setText(String.valueOf(count));
            user_dk_count.setVisibility(View.VISIBLE);
        }else if(!"".equals(videoUri) && list.size()>2 && i == 1){
            user_dk_count_text2.setText(String.valueOf(count));
            user_dk_count.setVisibility(View.VISIBLE);
        }else {
            user_dk_count.setVisibility(View.GONE);
        }
       /* DisplayImageOptions options = new DisplayImageOptions.Builder()//
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.RGB_565)//
                .build();
        ImageLoader.getInstance().displayImage(list.get(i),
                user_dk_child_img, options);*/
        /*if (list.size() > 2) {
            user_dk_child_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    imageBrower(i, list);
                }
            });
*/

        return view;
    }

        /**
         * 打开图片查看器
         *
         * @param position
         * @param urls2
         */
       /* protected void imageBrower ( int position, List<String > urls2){
            Intent intent = new Intent(mContext, ImagePagerActivity.class);
            // 图片url
            intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, (Serializable) urls2);
            intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, position);
            mContext.startActivity(intent);
        }*/



}
